import { IPSControl } from '../ipscontrol';
import { PSAjaxControlContainerImpl } from '../psajax-control-container-impl';
import { IPSDBPortletPart } from './ipsdbportlet-part';
import { IPSLayoutPos } from '../layout/ipslayout-pos';
import { IPSLanguageRes } from '../../res/ipslanguage-res';
import { IPSSysImage } from '../../res/ipssys-image';
import { IPSSysUniRes } from '../../security/ipssys-uni-res';
import { IPSUIActionGroup } from '../../view/ipsuiaction-group';

export class PSDBPortletPartImpl extends PSAjaxControlContainerImpl implements IPSDBPortletPart {
  get actionGroupExtractMode(): 'ITEM' | 'ITEMS' {
    return this.M.actionGroupExtractMode;
  }

  protected contentpscontrol: IPSControl | null = null;

  getContentPSControl(): IPSControl | null {
    if (this.contentpscontrol != null) return this.contentpscontrol;
    const value = this.M.getContentPSControl;
    if (value == null) {
      return null;
    }
    this.contentpscontrol = this.findPSControl(value);
    return this.contentpscontrol;
  }

  get contentPSControl(): IPSControl | null {
    return this.getContentPSControl();
  }

  getContentPSControlMust(): IPSControl {
    const value = this.getContentPSControl();
    if (value == null) {
      throw new Error('未指定内容部件');
    }
    return value;
  }

  get dynaClass(): string {
    return this.M.dynaClass;
  }

  get height(): number {
    return this.M.height != null ? this.M.height : 0.0;
  }

  protected pslayoutpos: IPSLayoutPos | null = null;

  getPSLayoutPos(): IPSLayoutPos | null {
    if (this.pslayoutpos != null) return this.pslayoutpos;
    const value = this.M.getPSLayoutPos;
    if (value == null) {
      return null;
    }
    this.pslayoutpos = this.getPSModel4('control.layout.IPSLayoutPos', value, 'getPSLayoutPos') as IPSLayoutPos;
    return this.pslayoutpos;
  }

  get psLayoutPos(): IPSLayoutPos | null {
    return this.getPSLayoutPos();
  }

  getPSLayoutPosMust(): IPSLayoutPos {
    const value = this.getPSLayoutPos();
    if (value == null) {
      throw new Error('未指定部件位置');
    }
    return value;
  }

  protected pssysimage: IPSSysImage | null = null;

  getPSSysImage(): IPSSysImage | null {
    if (this.pssysimage != null) return this.pssysimage;
    const value = this.M.getPSSysImage;
    if (value == null) {
      return null;
    }
    this.pssysimage = this.getPSModel4('res.IPSSysImage', value, 'getPSSysImage') as IPSSysImage;
    return this.pssysimage;
  }

  get psSysImage(): IPSSysImage | null {
    return this.getPSSysImage();
  }

  getPSSysImageMust(): IPSSysImage {
    const value = this.getPSSysImage();
    if (value == null) {
      throw new Error('未指定系统图片');
    }
    return value;
  }

  protected pssysunires: IPSSysUniRes | null = null;

  getPSSysUniRes(): IPSSysUniRes | null {
    if (this.pssysunires != null) return this.pssysunires;
    const value = this.M.getPSSysUniRes;
    if (value == null) {
      return null;
    }
    this.pssysunires = this.getPSModel4('security.IPSSysUniRes', value, 'getPSSysUniRes') as IPSSysUniRes;
    return this.pssysunires;
  }

  get psSysUniRes(): IPSSysUniRes | null {
    return this.getPSSysUniRes();
  }

  getPSSysUniResMust(): IPSSysUniRes {
    const value = this.getPSSysUniRes();
    if (value == null) {
      throw new Error('未指定系统统一资源');
    }
    return value;
  }

  protected psuiactiongroup: IPSUIActionGroup | null = null;

  getPSUIActionGroup(): IPSUIActionGroup | null {
    if (this.psuiactiongroup != null) return this.psuiactiongroup;
    const value = this.M.getPSUIActionGroup;
    if (value == null) {
      return null;
    }
    this.psuiactiongroup = this.getPSModel4('view.IPSUIActionGroup', value, 'getPSUIActionGroup') as IPSUIActionGroup;
    return this.psuiactiongroup;
  }

  get psUIActionGroup(): IPSUIActionGroup | null {
    return this.getPSUIActionGroup();
  }

  getPSUIActionGroupMust(): IPSUIActionGroup {
    const value = this.getPSUIActionGroup();
    if (value == null) {
      throw new Error('未指定界面行为组对象');
    }
    return value;
  }

  get portletType(): 'LIST' | 'CHART' | 'VIEW' | 'HTML' | 'TOOLBAR' | 'ACTIONBAR' | 'CUSTOM' | 'APPMENU' | 'CONTAINER' | 'RAWITEM' {
    return this.M.portletType;
  }

  get title(): string {
    return this.M.title;
  }

  get titleBarCloseMode(): 0 | 1 | 2 {
    return this.M.titleBarCloseMode != null ? this.M.titleBarCloseMode : 0;
  }

  protected titlepslanguageres: IPSLanguageRes | null = null;

  getTitlePSLanguageRes(): IPSLanguageRes | null {
    if (this.titlepslanguageres != null) return this.titlepslanguageres;
    const value = this.M.getTitlePSLanguageRes;
    if (value == null) {
      return null;
    }
    this.titlepslanguageres = this.getPSModel4('res.IPSLanguageRes', value, 'getTitlePSLanguageRes') as IPSLanguageRes;
    return this.titlepslanguageres;
  }

  get titlePSLanguageRes(): IPSLanguageRes | null {
    return this.getTitlePSLanguageRes();
  }

  getTitlePSLanguageResMust(): IPSLanguageRes {
    const value = this.getTitlePSLanguageRes();
    if (value == null) {
      throw new Error('未指定抬头语言资源');
    }
    return value;
  }

  get showTitleBar(): boolean {
    return this.M.showTitleBar;
  }

  get cls(): string {
    return 'PSDBPortletPartImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'control.IPSUserControl' || cls == 'control.dashboard.IPSDBPortletPart' || cls == 'control.layout.IPSLayoutItem') return true;
    return super.instanceof(cls);
  }
}
